<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>导入选手</title>
    <link rel="stylesheet" href="../utils/bootstrap-5.3.3-dist/css/bootstrap.min.css">
    <script src="../utils/bootstrap-5.3.3-dist/js/bootstrap.min.js"></script>
    <link rel="stylesheet" href="../utils/icon/iconfont.css">
    <link rel="stylesheet" href="../css/shared.css">
    <style>
        /*中部布局*/
        .central-layout {
            display: grid;
            grid-template-rows: 70px 470px 50px;
            width: 100%;
            margin: 0 auto;
        }

        /**
        中部头部布局
         */
        .central-head {
            display: flex;
            flex-direction: row;
            align-items: center;
            gap: 10px;
            padding: 5px;
        }

        /**
        表项限宽
         */
        .table td {
            max-width: 10vw;
        }

        .person-project {
            text-align: center;
            border: black solid 1px;
        }

        .project-mulbox {
            display: flex;
            justify-content: center;
            gap: 4px;
        }

    </style>
</head>
<body>
<div class="body-grid">
    <!--头部-->
    <div class="header-grid">
        <!--    返回按钮-->
        <div>
            <button class="btn btn-secondary iconfont go-back-button" onclick="window.location.href='group.html';">
                &#xe623;
            </button>
        </div>
        <!--    标题-->
        <div class="page-title" id="page-title">
            <script>
                document.getElementById("page-title").innerText=window.sessionStorage.getItem("competitionName")
                +"--导入选手"
            </script>
        </div>
        <div></div>
    </div>
    <!--中部-->
    <div class="central-layout">
        <div class="central-head">
            <button id="del-bh" class="btn btn-danger" style="float: left;margin-top: 15px;"
                    onclick="openDialog('del-batch-group-dialog')">
                批量删除
            </button>
            <!--                搜索框组件-->
            <div style="width: 700px;margin: auto">
                <div class="input-group">
                    <input id="search-input" type="text" class="form-control" placeholder="可按选手姓名、身份证号、组别、参赛单位、参赛项目、接力队伍进行搜索 . . .">
                    <button class="btn btn-outline-secondary iconfont" type="button" onclick="showSearch()">&#xe60a;
                    </button>
                </div>
            </div>
            <button class="btn btn-primary" onclick="openAddAthleteDialog()" id="addAthle">
                补增选手
            </button>
            <button class="btn btn-primary" onclick="downloadTemplate()">
                导出模板
            </button>
            <button class="btn btn-primary" onclick="uploadAthletes()" id="loadAth">
                导入选手
            </button>
        </div>
        <div class="table-responsive">
            <table id="athlete-table" class="table table-sm table-bordered text-center">
                <thead>
                <tr>
                    <th>
                        <label>
                            全选
                            <input type="checkbox" onclick="selectMul('athlete-table')">
                        </label>
                    </th>
                    <th>姓名</th>
                    <th>项目</th>
                    <th>组别</th>
                    <th>性别</th>
                    <th>身份证号</th>
                    <th>选手电话</th>
                    <th>参赛单位</th>
                    <th>负责人</th>
                    <th>单位电话</th>
                    <th>接力队伍</th>
                    <th>替补</th>
                    <th>操作</th>
                </tr>
                </thead>
                <tbody id="athlete-tbody" class="table-group-divider">
                </tbody>
            </table>
        </div>
        <div>
            <!--    分页组件-->
            <ul class="pagination page-ul-flex" id="pagination">
            </ul>
        </div>
    </div>
    <!--尾部-->
    <div class="footer-grid">
        <!--网格留空-->
        <div></div>
        <!--进度条-->
        <div id="progress-bar" class="progress-bar-flex">
            <div class="progress-bar-grid">
                <button type="button" class="btn btn-success progress-bar-button" disabled></button>
                <div class="progress-bar-text">新增赛事</div>
                <i class="iconfont progress-bar-arrow">&#xe604;</i>
            </div>
            <div class="progress-bar-grid">
                <button type="button" class="btn btn-success progress-bar-button" disabled></button>
                <div class="progress-bar-text">新增项目</div>
                <i class="iconfont progress-bar-arrow">&#xe604;</i>
            </div>
            <div class="progress-bar-grid">
                <button type="button" class="btn btn-success progress-bar-button" disabled></button>
                <div class="progress-bar-text">设置组别</div>
                <i class="iconfont progress-bar-arrow">&#xe604;</i>
            </div>
            <div class="progress-bar-grid">
                <button type="button" class="btn btn-success progress-bar-button" disabled></button>
                <div class="progress-bar-text">导入选手</div>
                <i class="iconfont progress-bar-arrow">&#xe604;</i>
            </div>
            <div class="progress-bar-grid">
                <button type="button" class="btn btn-success progress-bar-button" disabled></button>
                <div class="progress-bar-text">下发号码</div>
                <i class="iconfont progress-bar-arrow">&#xe604;</i>
            </div>
            <div class="progress-bar-grid">
                <button type="button" class="btn btn-success progress-bar-button" disabled></button>
                <div class="progress-bar-text">制卡</div>
                <i class="iconfont progress-bar-arrow">&#xe604;</i>
            </div>
            <div class="progress-bar-grid">
                <button type="button" class="btn btn-success progress-bar-button" disabled></button>
                <div class="progress-bar-text">签到</div>
                <i class="iconfont progress-bar-arrow">&#xe604;</i>
            </div>
            <div class="progress-bar-grid">
                <button type="button" class="btn btn-success progress-bar-button" disabled></button>
                <div class="progress-bar-text">批次管理</div>
                <i class="iconfont progress-bar-arrow">&#xe604;</i>
            </div>
            <div class="progress-bar-grid">
                <button type="button" class="btn btn-success progress-bar-button" disabled></button>
                <div class="progress-bar-text">规则设置</div>
                <i class="iconfont progress-bar-arrow">&#xe604;</i>
            </div>
            <div class="progress-bar-grid">
                <button type="button" class="btn btn-success progress-bar-button" disabled></button>
                <div class="progress-bar-text">开始比赛</div>
                <i class="iconfont progress-bar-arrow">&#xe604;</i>
            </div>
            <div class="progress-bar-grid">
                <button type="button" class="btn btn-success progress-bar-button" disabled></button>
                <div class="progress-bar-text">成绩计算</div>
                <i class="iconfont progress-bar-arrow" style="visibility: hidden;">&#xe604;</i>
            </div>
        </div>
        <!--   下一步-->
        <div>
            <button class="btn btn-primary iconfont next-button" onclick="nextProgress(NUMBER_PROGRESS,'number.html')" id="btn-progress">
                &#xe65b;
            </button>
        </div>
    </div>
</div>
<!--单个删除弹窗-->
<div id="del-one-group-dialog" class="my-dialog my-dialog-smaller" style="display: none">
    <div class="my-dialog-header">
        <!--                    标题占位-->
        <span>确定要删除吗？</span>
        <button type="button" class="btn-close close-icon"
                onclick="closeDialog('del-one-group-dialog')"></button>
    </div>
    <div class="my-dialog-body">
    </div>
    <div class="my-dialog-footer">
        <button type="button" class="btn btn-secondary btn-sm my-dialog-ft-btn"
                onclick="closeDialog('del-one-group-dialog')">取消
        </button>
        <button type="button" class="btn btn-primary btn-sm my-dialog-ft-btn"
                onclick="deleteOneGroup('del-one-group-dialog')">确认
        </button>
    </div>
</div>

<!--新增弹窗-->
<div id="add-athlete-dialog" class="my-dialog" style="display: none">
    <div class="my-dialog-header">
        <!--                    标题占位-->
        <span>补增选手</span>
        <button type="button" class="btn-close close-icon"
                onclick="closeAddAthleteDialog()"></button>
    </div>
    <div class="my-dialog-body">
        <div class="input-layout">
            <div class="label-area">
                <label for="athlete-name">姓名<span style="color:red;">*</span>：</label>
            </div>
            <div class="input-area">
                <input type="text" id="athlete-name" name="name" style="width: 100%">
            </div>
            <div class="err-area">
                <!--    长度不大于30字      -->
                <small style="color: red;"></small>
            </div>
        </div>
        <div class="input-layout">
            <div class="label-area">
                <label for="athlete-phone">电话<span style="color:red;">*</span>：</label>
            </div>
            <div class="input-area">
                <input type="text" id="athlete-phone" name="phone" style="width: 100%">
            </div>
            <div class="err-area">
                <!--                            长度不大于11字！-->
                <small style="color: red;"></small>
            </div>
        </div>
        <div class="input-layout">
            <div class="label-area">
                <label for="athlete-identity">身份证号<span style="color:red;">*</span>：</label>
            </div>
            <div class="input-area">
                <input type="text" id="athlete-identity" name="identity" style="width: 100%">
            </div>
            <div class="err-area">
                <!--                            长度不大于18字！-->
                <small style="color: red;"></small>
            </div>
        </div>
        <div class="input-layout">
            <div class="label-area">
                <label for="athlete-gender">性别：</label>
            </div>
            <div class="input-area">
                <select id="athlete-gender" name="gender" onchange="changeAthleteGender(this.value)">
                    <option value="男" selected>男</option>
                    <option value="女">女</option>
                </select>
            </div>
            <div class="err-area">
                <small style="color: red;"></small>
            </div>
        </div>
        <div class="input-layout">
            <div class="label-area">
                <label for="athlete-group">组别：</label>
            </div>
            <div class="input-area">
                <select id="athlete-group" name="group" onchange="changeAthleteGroup()">
                    <option value="默认" selected>默认</option>
                </select>
            </div>
            <div class="err-area">
                <small style="color: red;"></small>
            </div>
        </div>
        <div class="input-layout">
            <div class="label-area">
                <div>个人项目：</div>
            </div>
            <div class="input-area">
                <div class="person-project">
                    <div>80m个人</div>
                    <div class="project-mulbox">
                        <label style="display: none;">
                            <input type="checkbox" name="projects" value="标准距离-80m-个人">标准距离
                        </label>
                        <label style="display: none;">
                            <input type="checkbox" name="projects" value="中距离-80m-个人">中距离
                        </label>
                        <label style="display: none;">
                            <input type="checkbox" name="projects" value="短距离-80m-个人">短距离
                        </label>
                        <label style="display: none;">
                            <input type="checkbox" name="projects" value="快速-80m-个人">快速
                        </label>
                        <label style="display: none;">
                            <input type="checkbox" name="projects" value="阳光-80m-个人">阳光
                        </label>
                    </div>
                </div>
                <div class="person-project">
                    <div>2m个人</div>
                    <div class="project-mulbox">
                        <label style="display: none;">
                            <input type="checkbox" name="projects" value="标准距离-2m-个人">标准距离
                        </label>
                        <label style="display: none;">
                            <input type="checkbox" name="projects" value="中距离-2m-个人">中距离
                        </label>
                        <label style="display: none;">
                            <input type="checkbox" name="projects" value="短距离-2m-个人">短距离
                        </label>
                        <label style="display: none;">
                            <input type="checkbox" name="projects" value="快速-2m-个人">快速
                        </label>
                        <label style="display: none;">
                            <input type="checkbox" name="projects" value="阳光-2m-个人">阳光
                        </label>
                    </div>
                </div>
            </div>
            <div class="err-area">
                <small id="add-project-err" style="color: red;"></small>
            </div>
        </div>
        <div class="input-layout">
            <div class="label-area">
                <label for="athlete-unit">单位：</label>
            </div>
            <div class="input-area">
                <select id="athlete-unit" name="unit" onchange="changeAthleteUnit(this.value)">
                </select>
            </div>
            <div class="err-area">
                <small style="color: red;"></small>
            </div>
        </div>
        <div class="input-layout">
            <div class="label-area">
                <label for="athlete-team">接力队伍：</label>
            </div>
            <div class="input-area">
                <select id="athlete-team" name="team" onchange="">
                    <option value="无队伍" selected>无队伍</option>
                </select>
            </div>
            <div class="err-area">
                <small style="color: red;"></small>
            </div>
        </div>

    </div>
    <div class="my-dialog-footer">
        <button type="button" class="btn btn-secondary btn-sm my-dialog-ft-btn"
                onclick="closeAddAthleteDialog()">取消
        </button>
        <button type="button" class="btn btn-primary btn-sm my-dialog-ft-btn"
                onclick="submitAddDialog()">确认
        </button>
    </div>
</div>
<!--编辑弹窗-->
<div id="edit-athlete-dialog" class="my-dialog" style="display: none">
    <div class="my-dialog-header">
        <!--                    标题占位-->
        <span>编辑选手</span>
        <button type="button" class="btn-close close-icon"
                onclick="closeEditAthleteDialog()"></button>
    </div>
    <div class="my-dialog-body">
        <div class="input-layout">
            <div class="label-area">
                <label for="edit-athlete-name">姓名<span style="color:red;">*</span>：</label>
            </div>
            <div class="input-area">
                <input type="text" id="edit-athlete-name" style="width: 100%">
            </div>
            <div class="err-area">
                <!--    长度不大于30字      -->
                <small style="color: red;"></small>
            </div>
        </div>
        <div class="input-layout">
            <div class="label-area">
                <label for="edit-athlete-phone">电话<span style="color:red;">*</span>：</label>
            </div>
            <div class="input-area">
                <input type="text" id="edit-athlete-phone" style="width: 100%">
            </div>
            <div class="err-area">
                <!--                            长度不大于11字！-->
                <small style="color: red;"></small>
            </div>
        </div>
        <div class="input-layout">
            <div class="label-area">
                <label for="edit-athlete-identity">身份证号<span style="color:red;">*</span>：</label>
            </div>
            <div class="input-area">
                <input type="text" id="edit-athlete-identity" style="width: 100%">
            </div>
            <div class="err-area">
                <!--                            长度不大于18字！-->
                <small style="color: red;"></small>
            </div>
        </div>
        <div class="input-layout">
            <div class="label-area">
                <label for="edit-athlete-gender">性别：</label>
            </div>
            <div class="input-area">
                <select id="edit-athlete-gender" disabled>
                    <option value="男">男</option>
                    <option value="女">女</option>
                </select>
            </div>
            <div class="err-area">
                <small style="color: red;"></small>
            </div>
        </div>
        <div class="input-layout">
            <div class="label-area">
                组别：
            </div>
            <div class="input-area">
                <span id="edit-athlete-group"></span>
            </div>
            <div class="err-area">
                <small style="color: red;"></small>
            </div>
        </div>
        <div class="input-layout">
            <div class="label-area">
                <div>个人项目：</div>
            </div>
            <div class="input-area">
                <div class="person-project">
                    <div>80m个人</div>
                    <div class="project-mulbox">
                        <label style="display: none;">
                            <input type="checkbox" name="edit-projects" value="标准距离-80m-个人">标准距离
                        </label>
                        <label style="display: none;">
                            <input type="checkbox" name="edit-projects" value="中距离-80m-个人">中距离
                        </label>
                        <label style="display: none;">
                            <input type="checkbox" name="edit-projects" value="短距离-80m-个人">短距离
                        </label>
                        <label style="display: none;">
                            <input type="checkbox" name="edit-projects" value="快速-80m-个人">快速
                        </label>
                        <label style="display: none;">
                            <input type="checkbox" name="edit-projects" value="阳光-80m-个人">阳光
                        </label>
                    </div>
                </div>
                <div class="person-project">
                    <div>2m个人</div>
                    <div class="project-mulbox">
                        <label style="display: none;">
                            <input type="checkbox" name="edit-projects" value="标准距离-2m-个人">标准距离
                        </label>
                        <label style="display: none;">
                            <input type="checkbox" name="edit-projects" value="中距离-2m-个人">中距离
                        </label>
                        <label style="display: none;">
                            <input type="checkbox" name="edit-projects" value="短距离-2m-个人">短距离
                        </label>
                        <label style="display: none;">
                            <input type="checkbox" name="edit-projects" value="快速-2m-个人">快速
                        </label>
                        <label style="display: none;">
                            <input type="checkbox" name="edit-projects" value="阳光-2m-个人">阳光
                        </label>
                    </div>
                </div>
            </div>
            <div class="err-area">
                <small id="edit-project-err" style="color: red;"></small>
            </div>
        </div>
        <div class="input-layout" style="display: none">
            <div class="label-area">
                <label for="edit-athlete-substitute">替补状态：</label>
            </div>
            <div class="input-area">
                <select id="edit-athlete-substitute" onchange="">
                    <option value="是">是</option>
                    <option value="否">否</option>
                </select>
            </div>
            <div class="err-area">
                <small style="color: red;"></small>
            </div>
        </div>

    </div>
    <div class="my-dialog-footer">
        <button type="button" class="btn btn-secondary btn-sm my-dialog-ft-btn"
                onclick="closeEditAthleteDialog()">取消
        </button>
        <button type="button" class="btn btn-primary btn-sm my-dialog-ft-btn"
                onclick="submitEditDialog()">确认
        </button>
    </div>
</div>

<!--批量删除弹窗-->
<div id="del-batch-group-dialog" class="my-dialog my-dialog-smaller" style="display: none">
    <div class="my-dialog-header">
        <!--                    标题占位-->
        <span>确定要批量删除吗？</span>
        <button type="button" class="btn-close close-icon"
                onclick="closeDialog('del-batch-group-dialog')"></button>
    </div>
    <div class="my-dialog-body">
    </div>
    <div class="my-dialog-footer">
        <button type="button" class="btn btn-secondary btn-sm my-dialog-ft-btn"
                onclick="closeDialog('del-batch-group-dialog')">取消
        </button>
        <button type="button" class="btn btn-primary btn-sm my-dialog-ft-btn"
                onclick="deleteBatchGroup('athlete-table','del-batch-group-dialog')">确认
        </button>
    </div>
</div>

<script src="../js/pages.js"></script>
<script src="../api/urls.js"></script>
<script src="../js/dialog.js"></script>
<script src="../js/progress.js"></script>
<script>
    updateProgress("progress-bar", ATHLETE_PROGRESS);

    //页码
    let pageNum = 1;
    //一页多少条
    let pageSize = 20;
    //总条数
    let total;
    //总页数
    let pages;
    //请求记录
    let records;
    //删除id
    let delId;
    //更新id
    let updateId;
    //搜索内容
    let searchAll;
	//排除组别
	let excludeGroupName=["公开组","DXW","DXM","小学低年级组","小学高年级组","初中组","高中组","大学组"]


    /**
     * 多选框实现
     */
     function selectMul(tableId) {
        let mulSelect = document.querySelector("#" + tableId + " thead input");
        let trs = document.querySelectorAll("#" + tableId + " tbody>tr");
        for (let tr of trs) {
            tr.firstElementChild.firstElementChild.checked = mulSelect.checked;
        }
    }

    /**
     * 批量删除
     */
     async function deleteBatchGroup(tableId, dialogId) {
        let deleteIds = [];
        let trs = document.querySelectorAll("#" + tableId + " tbody>tr");
        for (let tr of trs) {
            if (tr.firstElementChild.firstElementChild.checked) {
                deleteIds.push(Number(tr.dataset.athleteId));
            }
        }
        closeDialog(dialogId);
        if (deleteIds.length !== 0) {
            await fetch(ATHLETE_URL + DELETE_BATCH_URL, {
                method: "POST",
                headers: new Headers({"Content-Type": "application/json"}),
                body: JSON.stringify(deleteIds)
            });
            await showPage();
            window.location.href='athlete.html'
        }
    }

    /**
     * 点击搜索
     */
    async function showSearch(){
        pageNum=1;
        await showPage();
    }

    /**
     * 打开编辑弹窗
     */
    async function openEditAthleteDialog(record) {
        let name = document.getElementById("edit-athlete-name");
        name.value = record.athleteName;
        let phone = document.getElementById("edit-athlete-phone");
        phone.value = record.athletePhone;
        let identity = document.getElementById("edit-athlete-identity");
        identity.value = record.idNumber;
        if (record.substitute) {
            let substitute = document.getElementById("edit-athlete-substitute");
            substitute.parentElement.parentElement.removeAttribute("style");
            substitute.value = record.substitute;
        }
        let group = document.getElementById("edit-athlete-group");
        group.textContent = record.groupName;
        let gender = document.getElementById("edit-athlete-gender");
        gender.value = record.gender;
        let projects = document.querySelectorAll("#edit-athlete-dialog input[name='edit-projects']");
        for (let project of projects) {
            if (record.projectNames.includes(project.value)) {
                project.checked = true;
            }
        }
        let url = new URL(PROJECT_URL + GET_URL);
        url.searchParams.set("competitionId", window.sessionStorage.getItem("competitionId"));
        await fetch(url).then(res => {
            return res.json()
        }).then(projectList => {
            for (const projectListElement of projectList) {
                if (projectListElement.category === 0) {//个人
                    let element;
                    if (projectListElement.frequency === 0) {//80m
                        switch (projectListElement.type) {
                            /**
                             0：短距离<br>
                             1：中距离<br>
                             2：标准距离<br>
                             3：快速
                             */
                            case 0:
                                element = document.querySelector(
                                    "input[type='checkbox'][name='edit-projects'][value='短距离-80m-个人']");
                                break;
                            case 1:
                                element = document.querySelector(
                                    "input[type='checkbox'][name='edit-projects'][value='中距离-80m-个人']");
                                break;
                            case 2:
                                element = document.querySelector(
                                    "input[type='checkbox'][name='edit-projects'][value='标准距离-80m-个人']");
                                break;
                            case 3:
                                element = document.querySelector(
                                    "input[type='checkbox'][name='edit-projects'][value='快速-80m-个人']");
                                break;
                            case 4:
                                element = document.querySelector(
                                    "input[type='checkbox'][name='edit-projects'][value='阳光-80m-个人']");
                                break;
                            default:
                                console.log("数据错误")
                                break;
                        }
                    } else {//2m
                        switch (projectListElement.type) {
                            /**
                             0：短距离<br>
                             1：中距离<br>
                             2：标准距离<br>
                             3：快速
                             */
                            case 0:
                                element = document.querySelector(
                                    "input[type='checkbox'][name='edit-projects'][value='短距离-2m-个人']");
                                break;
                            case 1:
                                element = document.querySelector(
                                    "input[type='checkbox'][name='edit-projects'][value='中距离-2m-个人']");
                                break;
                            case 2:
                                element = document.querySelector(
                                    "input[type='checkbox'][name='edit-projects'][value='标准距离-2m-个人']");
                                break;
                            case 3:
                                element = document.querySelector(
                                    "input[type='checkbox'][name='edit-projects'][value='快速-2m-个人']");
                                break;
                            case 4:
                                element = document.querySelector(
                                    "input[type='checkbox'][name='edit-projects'][value='阳光-2m-个人']");
                                break;
                            default:
                                console.log("数据错误")
                                break;
                        }
                    }
                    element.parentElement.removeAttribute("style");
                    element.dataset.projectId = projectListElement.id;
                }
            }
        });
        openDialog("edit-athlete-dialog");
    }

    /**
     * 校验编辑数据
     */
    async function verifyEditData() {
        let smalls = document.querySelectorAll("#edit-athlete-dialog small");
        for (let small of smalls) {
            small.textContent = "";
        }
        let flag = true;
        let athleteName = document.getElementById("edit-athlete-name");
        if (athleteName.value && athleteName.value.trim() !== athleteName.value) {
            athleteName.parentElement.parentElement.lastElementChild.firstElementChild.textContent = "名字前后不能有空格！";
            flag = false;
        }
        if (athleteName.value && athleteName.value.trim().length !== 0) {
            if (athleteName.value.trim().length > 30) {
                athleteName.parentElement.parentElement.lastElementChild.firstElementChild.textContent = "名字长度不能超过30个字！";
                flag = false;
            }
        } else {
            athleteName.parentElement.parentElement.lastElementChild.firstElementChild.textContent = "名字不能为空！";
            flag = false;
        }
        let athletePhone = document.getElementById("edit-athlete-phone");
        if (athletePhone.value && athletePhone.value.trim() !== athletePhone.value) {
            athletePhone.parentElement.parentElement.lastElementChild.firstElementChild.textContent = "电话前后不能有空格！";
            flag = false;
        }
        if (athletePhone.value && athletePhone.value.trim().length !== 0) {
            if (athletePhone.value.trim().length > 11) {
                athletePhone.parentElement.parentElement.lastElementChild.firstElementChild.textContent = "电话号码不能超过11位！";
                flag = false;
            }
        } else {
            athletePhone.parentElement.parentElement.lastElementChild.firstElementChild.textContent = "电话不能为空！";
            flag = false;
        }
        let athleteIdentity = document.getElementById("edit-athlete-identity");
        if (athleteIdentity.value && athleteIdentity.value.trim() !== athleteIdentity.value) {
            athleteIdentity.parentElement.parentElement.lastElementChild.firstElementChild.textContent = "身份证号前后不能有空格！";
            flag = false;
        }
        let group = document.getElementById("edit-athlete-group");
        if (athleteIdentity.value && athleteIdentity.value.trim().length !== 0) {
            if (!validateIDCard(athleteIdentity.value)) {
                athleteIdentity.parentElement.parentElement.lastElementChild.firstElementChild.textContent = "请检查身份证号是否正确！";
                flag = false;
            } else {
                let url1 = new URL(ATHLETE_URL + "/getByIdNum");
                url1.searchParams.set("competitionId", window.sessionStorage.getItem("competitionId"));
                url1.searchParams.set("identity", athleteIdentity.value);
                await fetch(url1).then(resp => {
                    return resp.json()
                }).then(result => {
                    if (result.id !== null && result.id !== updateId) {
                        athleteIdentity.parentElement.parentElement.lastElementChild.firstElementChild.textContent = "身份证号重复";
                        flag = false;
                    }
                })
				console.log(excludeGroupName.includes(group.textContent) )
                if (!excludeGroupName.includes(group.textContent)) {
                    let url = new URL(GROUP_URL + "/getGroupByAge");
                    url.searchParams.set("competitionId", window.sessionStorage.getItem("competitionId"));
                    url.searchParams.set("age", String(calculateAgeFromIDCard(athleteIdentity.value)));
                    url.searchParams.set("gender", String(document.getElementById("edit-athlete-gender").value));
                    await fetch(url).then(resp => {
                        return resp.json();
                    }).then(result => {
                        if (result.id) {
                            if (result.name !== group.textContent) {
                                athleteIdentity.parentElement.parentElement.lastElementChild.firstElementChild.textContent = "改变身份证号不能影响组别！";
                                flag = false;
                            }
                        } else {
                            athleteIdentity.parentElement.parentElement.lastElementChild.firstElementChild.textContent = "年龄不符合任何组别！";
                            flag = false;
                        }
                    });
                }

            }
        } else {
            athleteIdentity.parentElement.parentElement.lastElementChild.firstElementChild.textContent = "身份证号不能为空！";
            flag = false;
        }
        if (group.textContent === "公开组") {
            let projects = document.querySelectorAll("#edit-athlete-dialog input[name='edit-projects']");
            let bo = false;
            for (let project of projects) {
                if (project.checked) {
                    bo = true;
                    break;
                }
            }
            if (!bo) {
                let smallerr = document.getElementById("edit-project-err");
                smallerr.textContent = "公开组不能不选择个人项目！";
                flag = false;
            }
        }
        let substitute = document.getElementById("edit-athlete-substitute");
        if (substitute.value === "否") {
            let url2 = new URL(ATHLETE_TEAM_URL + "/checkCountByAthleteId");
            url2.searchParams.set("athleteId", updateId);
            await fetch(url2).then(resp => {
                return resp.text();
            })
                .then(result => {
                    if (result === "no") {
                        substitute.parentElement.parentElement.lastElementChild.firstElementChild.textContent = "非替补人数不能超过3人！";
                        flag = false;
                    }
                })
        }
        return flag;
    }

    /**
     * 提交编辑弹窗
     */
    async function submitEditDialog() {
        if (!await verifyEditData()) {
            return;
        }
        let bodyObject = {};
        let name = document.getElementById("edit-athlete-name");
        let phone = document.getElementById("edit-athlete-phone");
        let identity = document.getElementById("edit-athlete-identity");
        let substitute = document.getElementById("edit-athlete-substitute");
        let projects = document.querySelectorAll("#edit-athlete-dialog input[name='edit-projects']");
        let projectIds = [];
        for (let project of projects) {
            if (project.checked) {
                projectIds.push(project.dataset.projectId);
            }
        }
        bodyObject.name = name.value;
        bodyObject.phone = phone.value;
        bodyObject.identity = identity.value;
        if (substitute.parentElement.parentElement.style.display !== "none") {
            bodyObject.substitute = substitute.value;
        }
        bodyObject.projectIds = projectIds;
        bodyObject.id = updateId;
        await fetch(ATHLETE_URL + "/editOne", {
            method: "POST",
            headers: new Headers({"Content-Type": "application/json"}),
            body: JSON.stringify(bodyObject)
        });
        closeEditAthleteDialog();
        await showPage();
    }

    /**
     * 关闭编辑弹窗
     */
    function closeEditAthleteDialog() {
        let smalls = document.querySelectorAll("#edit-athlete-dialog small");
        for (let small of smalls) {
            small.textContent = "";
        }
        let name = document.getElementById("edit-athlete-name");
        name.value = null;
        let phone = document.getElementById("edit-athlete-phone");
        phone.value = null;
        let identity = document.getElementById("edit-athlete-identity");
        identity.value = null;
        let group = document.getElementById("edit-athlete-group");
        group.textContent = null;
        let projects = document.querySelectorAll("#edit-athlete-dialog input[name='edit-projects']");
        for (let project of projects) {
            project.parentElement.style.display = "none";
            project.checked = false;
            project.removeAttribute("data-project-id");
        }
        let substitute = document.getElementById("edit-athlete-substitute");
        substitute.parentElement.parentElement.style.display = "none";
        closeDialog("edit-athlete-dialog");
    }

    /**
     * 校验补增数据
     */
    async function verifyAddData() {
        let smalls = document.querySelectorAll("#add-athlete-dialog small");
        for (let small of smalls) {
            small.textContent = "";
        }
        let flag = true;
        let athleteName = document.getElementById("athlete-name");
        if (athleteName.value && athleteName.value.trim() !== athleteName.value) {
            athleteName.parentElement.parentElement.lastElementChild.firstElementChild.textContent = "名字前后不能有空格！";
            flag = false;
        }
        if (athleteName.value && athleteName.value.trim().length !== 0) {
            if (athleteName.value.trim().length > 30) {
                athleteName.parentElement.parentElement.lastElementChild.firstElementChild.textContent = "名字长度不能超过30个字！";
                flag = false;
            }
        } else {
            athleteName.parentElement.parentElement.lastElementChild.firstElementChild.textContent = "名字不能为空！";
            flag = false;
        }
        let athletePhone = document.getElementById("athlete-phone");
        if (athletePhone.value && athletePhone.value.trim() !== athletePhone.value) {
            athletePhone.parentElement.parentElement.lastElementChild.firstElementChild.textContent = "电话前后不能有空格！";
            flag = false;
        }
        if (athletePhone.value && athletePhone.value.trim().length !== 0) {
            if (athletePhone.value.trim().length > 11) {
                athletePhone.parentElement.parentElement.lastElementChild.firstElementChild.textContent = "电话号码不能超过11位！";
                flag = false;
            }
        } else {
            athletePhone.parentElement.parentElement.lastElementChild.firstElementChild.textContent = "电话不能为空！";
            flag = false;
        }
        let athleteIdentity = document.getElementById("athlete-identity");
        if (athleteIdentity.value && athleteIdentity.value.trim() !== athleteIdentity.value) {
            athleteIdentity.parentElement.parentElement.lastElementChild.firstElementChild.textContent = "身份证号前后不能有空格！";
            flag = false;
        }
        if (athleteIdentity.value && athleteIdentity.value.trim().length !== 0) {
            if (!validateIDCard(athleteIdentity.value)) {
                athleteIdentity.parentElement.parentElement.lastElementChild.firstElementChild.textContent = "请检查身份证号是否正确！";
                flag = false;
            } else {
                let url1 = new URL(ATHLETE_URL + "/check");
                url1.searchParams.set("competitionId", window.sessionStorage.getItem("competitionId"));
                url1.searchParams.set("identity", athleteIdentity.value);
                await fetch(url1).then(resp => {
                    return resp.text()
                }).then(result => {
                    if (result === "no") {
                        athleteIdentity.parentElement.parentElement.lastElementChild.firstElementChild.textContent = "身份证号重复";
                        flag = false;
                    }
                })
                let group = document.getElementById("athlete-group");
                if (group.value === "默认") {
                    let url = new URL(GROUP_URL + "/getByAge");
                    url.searchParams.set("competitionId", window.sessionStorage.getItem("competitionId"));
                    url.searchParams.set("age", String(calculateAgeFromIDCard(athleteIdentity.value)));
                    url.searchParams.set("gender", String(document.getElementById("athlete-gender").value));
                    await fetch(url).then(resp => {
                        return resp.json();
                    }).then(result => {
                        if (result.groupId) {
                            group.dataset.groupId = result.groupId;
                        } else {
                            athleteIdentity.parentElement.parentElement.lastElementChild.firstElementChild.textContent = "年龄不符合任何组别！";
                            flag = false;
                        }
                    })
                } else {
                    let url = new URL(GROUP_URL + "/getByName");
                    url.searchParams.set("competitionId", window.sessionStorage.getItem("competitionId"));
                    url.searchParams.set("groupName", String(group.value));
                    url.searchParams.set("gender", String(document.getElementById("athlete-gender").value));
                    await fetch(url).then(resp => {
                        return resp.json();
                    }).then(result => {
                        if (result.groupId) {
                            group.dataset.groupId = result.groupId;
                        } else {
                            athleteIdentity.parentElement.parentElement.lastElementChild.firstElementChild.textContent = "没有该组别/可能是服务器错误！";
                            flag = false;
                        }
                    })
                }

            }
        } else {
            athleteIdentity.parentElement.parentElement.lastElementChild.firstElementChild.textContent = "身份证号不能为空！";
            flag = false;
        }
        let athleteTeam = document.getElementById("athlete-team");
        let athleteGroup = document.getElementById("athlete-group");
        if (athleteTeam.value === "无队伍" || athleteGroup.value === "公开组") {
            let bo = false;
            let elementNodeListOf = document.querySelectorAll("#add-athlete-dialog input[name='projects']");
            for (let elementNodeListOfElement of elementNodeListOf) {
                if (elementNodeListOfElement.checked) {
                    bo = true;
                    break;
                }
            }
            if (!bo) {
                flag = false;
                document.getElementById("add-project-err").textContent = "不参加接力赛的同时不能不参加个人赛！";
            }
        } else {
            let url2 = new URL(ATHLETE_TEAM_URL + "/getGroupByTeamId");
            url2.searchParams.set("teamId", athleteTeam.value);
            await fetch(url2).then(resp => {
                return resp.json();
            }).then(result => {
                if (result.group && result.group.id !== Number(athleteGroup.dataset.groupId)) {
                    flag = false;
                    athleteTeam.parentElement.parentElement.lastElementChild.firstElementChild.textContent = "和接力队伍的组别不同！";
                }
            });
        }

        return flag;
    }

    /**
     * 校验身份证号
     */
    function validateIDCard(idCard) {
        // 验证身份证长度是否正确
        if (idCard.length !== 18) {
            return false;
        }

        // 校验前17位是否全是数字，第18位是否为数字或大写X
        if (!/^\d{17}[\dX]$/.test(idCard)) {
            return false;
        }
        // 权重因子
        const factor = [7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5, 8, 4, 2];
        // 校验码
        const parityBit = ['1', '0', 'X', '9', '8', '7', '6', '5', '4', '3', '2'];
        let sum = 0;

        for (let i = 0; i < 17; i++) {
            sum += parseInt(idCard.charAt(i), 10) * factor[i];
        }

        const modValue = sum % 11;
        const checkDigit = parityBit[modValue];

        if (checkDigit !== idCard.charAt(17).toUpperCase()) {
            return false;
        }
        let age = calculateAgeFromIDCard(idCard);
        if (!age || age <= 0) {
            return false;
        }
        return true;

    }

    /**
     * 计算年龄
     * @param idCard
     * @returns {number}
     */
    function calculateAgeFromIDCard(idCard) {

        // 获取出生日期部分（第7到14位）
        const birthDateStr = idCard.substring(6, 14);

        // 解析年、月、日
        const year = parseInt(birthDateStr.substring(0, 4), 10);
        const month = parseInt(birthDateStr.substring(4, 6), 10) - 1; // JavaScript的月份是从0开始的
        const day = parseInt(birthDateStr.substring(6, 8), 10);

        // 创建出生日期对象
        const birthDate = new Date(year, month, day);

        // 获取当前日期
        const today = new Date();

        // 计算年龄
        let age = today.getFullYear() - birthDate.getFullYear();
        const monthDiff = today.getMonth() - birthDate.getMonth();
        const dayDiff = today.getDate() - birthDate.getDate();

        // 如果生日还没到，则减去一年
        if (monthDiff < 0 || (monthDiff === 0 && dayDiff < 0)) {
            age--;
        }

        return age;
    }

    /**
     * 提交新增个人
     */
    async function submitAddDialog() {
        if (!await verifyAddData()) {
            return;
        }
        let bodyObject = {};
        let athleteName = document.getElementById("athlete-name");
        bodyObject.athleteName = athleteName.value;
        let athletePhone = document.getElementById("athlete-phone");
        bodyObject.phone = athletePhone.value;
        let athleteIdentity = document.getElementById("athlete-identity");
        bodyObject.identity = athleteIdentity.value;
        let athleteGender = document.getElementById("athlete-gender");
        bodyObject.gender = athleteGender.value;
        let athleteGroup = document.getElementById("athlete-group");
        bodyObject.groupId = athleteGroup.dataset.groupId;
        bodyObject.competitionId = window.sessionStorage.getItem("competitionId");
        if (athleteGroup.value !== "公开组") {
            bodyObject.unitId = document.getElementById("athlete-unit").value;
            let athleteTeam = document.getElementById("athlete-team");
            if (athleteTeam.value !== "无队伍") {
                bodyObject.teamId = athleteTeam.value;
            }
        }
        let projectIds = [];
        let projects = document.querySelectorAll("#add-athlete-dialog input[name='projects']");
        for (let project of projects) {
            if (project.checked) {
                projectIds.push(project.dataset.projectId);
            }
        }
        bodyObject.projectIds = projectIds;
        await fetch(ATHLETE_URL + "/addOne", {
            method: "POST",
            headers: new Headers({"Content-Type": "application/json"}),
            body: JSON.stringify(bodyObject)
        });
        closeAddAthleteDialog();
        document.getElementById("search-input").value = null;
        await showPage();
        modifyProgress(ATHLETE_PROGRESS,"athlete.html")
    }

    /**
     * 打开新增弹窗
     */
    async function openAddAthleteDialog() {
        let athleteUnit = document.getElementById("athlete-unit");
        let athleteGender = document.getElementById("athlete-gender");
        //搜索所有单位
        let url = new URL(UNIT_URL + "/getByCompetitionId");
        url.searchParams.set("competitionId", window.sessionStorage.getItem("competitionId"));
        await fetch(url).then(resp => {
            return resp.json();
        }).then(units => {
            for (let unit of units) {
                if (unit.name !== "无单位") {
                    let option = document.createElement("option");
                    option.value = unit.id;
                    option.textContent = unit.name;
                    athleteUnit.append(option);
                }
            }
        });
        await changePersonProject();
        await changeAthleteUnit(athleteUnit.value);
        await changeAthleteGender(athleteGender.value);
        openDialog('add-athlete-dialog');
    }

    /**
     * 改变个人项目的显示
     */
    async function changePersonProject() {
        let projects = document.querySelectorAll("#add-athlete-dialog input[name='projects']");
        for (let project of projects) {
            project.parentElement.style.display = "none";
        }
        let url = new URL(PROJECT_URL + GET_URL);
        url.searchParams.set("competitionId", window.sessionStorage.getItem("competitionId"));
        await fetch(url).then(res => {
            return res.json()
        }).then(projectList => {
            for (const projectListElement of projectList) {
                if (projectListElement.category === 0) {//个人
                    let element;
                    if (projectListElement.frequency === 0) {//80m
                        switch (projectListElement.type) {
                            /**
                             0：短距离<br>
                             1：中距离<br>
                             2：标准距离<br>
                             3：快速
                             */
                            case 0:
                                element = document.querySelector(
                                    "input[type='checkbox'][name='projects'][value='短距离-80m-个人']");
                                break;
                            case 1:
                                element = document.querySelector(
                                    "input[type='checkbox'][name='projects'][value='中距离-80m-个人']");
                                break;
                            case 2:
                                element = document.querySelector(
                                    "input[type='checkbox'][name='projects'][value='标准距离-80m-个人']");
                                break;
                            case 3:
                                element = document.querySelector(
                                    "input[type='checkbox'][name='projects'][value='快速-80m-个人']");
                                break;
                            case 4:
                                element = document.querySelector(
                                    "input[type='checkbox'][name='projects'][value='阳光-80m-个人']");
                                break;
                            default:
                                console.log("数据错误")
                                break;
                        }
                    } else {//2m
                        switch (projectListElement.type) {
                            /**
                             0：短距离<br>
                             1：中距离<br>
                             2：标准距离<br>
                             3：快速
                             */
                            case 0:
                                element = document.querySelector(
                                    "input[type='checkbox'][name='projects'][value='短距离-2m-个人']");
                                break;
                            case 1:
                                element = document.querySelector(
                                    "input[type='checkbox'][name='projects'][value='中距离-2m-个人']");
                                break;
                            case 2:
                                element = document.querySelector(
                                    "input[type='checkbox'][name='projects'][value='标准距离-2m-个人']");
                                break;
                            case 3:
                                element = document.querySelector(
                                    "input[type='checkbox'][name='projects'][value='快速-2m-个人']");
                                break;
                            case 4:
                                element = document.querySelector(
                                    "input[type='checkbox'][name='projects'][value='阳光-2m-个人']");
                                break;
                            default:
                                console.log("数据错误")
                                break;
                        }
                    }
                    element.parentElement.removeAttribute("style");
                    element.dataset.projectId = projectListElement.id;
                }
            }
        });
    }


    /**
     * 新增窗口改变性别
     */
    async function changeAthleteGender(value) {
        let athleteGroup = document.getElementById("athlete-group");
        athleteGroup.innerHTML = '<option value="默认" selected>默认</option>';
        let url = new URL(GROUP_URL + GET_URL);
        url.searchParams.set("competitionId", window.sessionStorage.getItem("competitionId"));
        await fetch(url).then(resp => {
            return resp.json()
        }).then(groups => {
            for (let group of groups) {
                if (group.name === "公开组") {
                    let option = document.createElement("option");
                    option.value = "公开组";
                    option.textContent = "公开组";
                    athleteGroup.append(option);
                } else if (group.name === "小学低年级组") {
                    let option = document.createElement("option");
                    option.value = "小学低年级组";
                    option.textContent = "小学低年级组";
                    athleteGroup.append(option);
                }else if (group.name === "小学高年级组") {
                    let option = document.createElement("option");
                    option.value = "小学高年级组";
                    option.textContent = "小学高年级组";
                    athleteGroup.append(option);
                }else if (group.name === "初中组") {
                    let option = document.createElement("option");
                    option.value = "初中组";
                    option.textContent = "初中组";
                    athleteGroup.append(option);
                }else if (group.name === "高中组") {
                    let option = document.createElement("option");
                    option.value = "高中组";
                    option.textContent = "高中组";
                    athleteGroup.append(option);
                }else if (group.name === "大学组") {
                    let option = document.createElement("option");
                    option.value = "大学组";
                    option.textContent = "大学组";
                    athleteGroup.append(option);
                }else if ((group.name === "DXW" && value === "女") || (group.name === "DXM" && value === "男")) {
                    let option = document.createElement("option");
                    option.value = "大学组";
                    option.textContent = "大学组";
                    athleteGroup.append(option);
                }
            }
        });
    }

    /**
     * 新增窗口改变单位
     */
    async function changeAthleteUnit(value) {
        if (value) {
            let athleteTeam = document.getElementById("athlete-team");
            athleteTeam.innerHTML = '<option value="无队伍" selected>无队伍</option>';
            //搜索所有组别
            let url = new URL(TEAM_URL + "/getByUnitId");
            url.searchParams.set("unitId", value);
            await fetch(url).then(resp => {
                return resp.json();
            }).then(teams => {
                for (let team of teams) {
                    let option = document.createElement("option");
                    option.value = team.id;
                    option.textContent = team.name;
                    athleteTeam.append(option);
                }
            })
        }

    }

    /**
     * 新增窗口改变组别
     */
    function changeAthleteGroup() {
        let athleteUnit = document.getElementById("athlete-unit");
        let athleteTeam = document.getElementById("athlete-team");
        let athleteGroup = document.getElementById("athlete-group");
        for (let child of athleteGroup.children) {
            if (child.selected === true) {
                if (child.textContent === "公开组") {
                    athleteUnit.parentElement.parentElement.style.display = "none";
                    athleteTeam.parentElement.parentElement.style.display = "none";
                } else {
                    athleteUnit.parentElement.parentElement.removeAttribute("style");
                    athleteTeam.parentElement.parentElement.removeAttribute("style");
                }
            }
        }
    }

    /**
     * 关闭新增弹窗
     */
    function closeAddAthleteDialog() {
        let athleteName = document.getElementById("athlete-name");
        athleteName.value = null;
        let athletePhone = document.getElementById("athlete-phone");
        athletePhone.value = null;
        let athleteIdentity = document.getElementById("athlete-identity");
        athleteIdentity.value = null;
        let athleteGroup = document.getElementById("athlete-group");
        athleteGroup.innerHTML = '<option value="默认" selected>默认</option>';
        athleteGroup.value = "默认";
        athleteGroup.removeAttribute("data-group-id");
        let athleteGender = document.getElementById("athlete-gender");
        athleteGender.value = "男";
        let projects = document.querySelectorAll("#add-athlete-dialog input[name='projects']");
        for (let project of projects) {
            project.checked = false;
            project.removeAttribute("data-project-id");
        }
        let athleteUnit = document.getElementById("athlete-unit");
        athleteUnit.innerHTML = "";
        athleteUnit.parentElement.parentElement.removeAttribute("style");
        let athleteTeam = document.getElementById("athlete-team");
        athleteTeam.innerHTML = '<option value="无队伍" selected>无队伍</option>';
        athleteTeam.parentElement.parentElement.removeAttribute("style");
        let smalls = document.querySelectorAll("#add-athlete-dialog small");
        for (let small of smalls) {
            small.textContent = "";
        }
        closeDialog('add-athlete-dialog');
    }

    /**
     * 单个删除
     */
    async function deleteOneGroup(dialogId) {
        closeDialog(dialogId);
        let url = new URL(ATHLETE_URL + "/deleteById");
        url.searchParams.set("id", delId);
        await fetch(url, {method: "POST"});
        await showPage();
    }

    /**
     * 下载模板
     */
    async function downloadTemplate() {
        await fetch(ATHLETE_URL + "/download").then(resp => {
            return resp.blob();
        }).then(blob => {
            // 创建一个指向 Blob 的 URL
            const url = window.URL.createObjectURL(blob);

            // 创建 <a> 元素
            const a = document.createElement('a');
            a.style.display = 'none';
            a.href = url;
            a.download = '模板.xlsx'; // 设置下载的文件名

            // 添加 <a> 到文档中，并触发点击事件
            document.body.appendChild(a);
            a.click();

            // 清理资源
            window.URL.revokeObjectURL(url);
            document.body.removeChild(a);
        });
    }

    /**
     * 上传选手
     * @returns {Promise<void>}
     */
    async function uploadAthletes() {
        // 创建input标签
        let input = document.createElement('input');
        input.type = "file";
        input.accept = ".xlsx,.xls";
        input.style.display = "none";
        document.body.append(input);
        input.click();
        input.addEventListener("change", async () => {
            if (input.files && input.files.length !== 0) {
                let formData = new FormData();
                formData.append("file", input.files[0]);
                formData.append("competitionId", window.sessionStorage.getItem("competitionId"));
                await fetch(ATHLETE_URL + "/upload", {
                    method: "POST",
                    body: formData
                }).then(resp => {
                    let content = resp.headers.get("content-type");
                    if (content === "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet;charset=utf-8") {
                        resp.blob().then(blob => {
                            // 创建一个指向 Blob 的 URL
                            const url = window.URL.createObjectURL(blob);

                            // 创建 <a> 元素
                            const a = document.createElement('a');
                            a.style.display = 'none';
                            a.href = url;
                            a.download = '错误数据.xlsx'; // 设置下载的文件名

                            // 添加 <a> 到文档中，并触发点击事件
                            document.body.appendChild(a);
                            a.click();

                            // 清理资源
                            window.URL.revokeObjectURL(url);
                            document.body.removeChild(a);
                        });
                    }
                });
                document.getElementById("search-input").value = null;
                //更新进度条
                
                await showPage();
                input.remove();
                modifyProgress(ATHLETE_PROGRESS,"athlete.html")
            }
        });
    }

    /**
     * 表格渲染
     */
    function drawAthleteTable(records) {
        let tableBody = document.getElementById("athlete-tbody");
        tableBody.innerHTML = "";
        for (let record of records) {
            let trElement = document.createElement("tr");
            trElement.dataset.athleteId = record.id;
            

            let tdElement0 = document.createElement("td");
            let inputElement = document.createElement("input");
            inputElement.type = "checkbox";
            tdElement0.append(inputElement);

            let tdElement1 = document.createElement("td");
            tdElement1.textContent = record.athleteName;
            let tdElement2 = document.createElement("td");
            let content = "";
            for (let projectName of record.projectNames) {
                content += projectName + ","
            }
            tdElement2.textContent = content.slice(0, -1);
            let tdElement3 = document.createElement("td");
            tdElement3.textContent = record.groupName;
            let htmlTableCellElement = document.createElement("td");
            htmlTableCellElement.textContent = record.gender;
            let tdElement4 = document.createElement("td");
            tdElement4.textContent = record.idNumber;
            let tdElement5 = document.createElement("td");
            tdElement5.textContent = record.athletePhone;
            let tdElement6 = document.createElement("td");
            tdElement6.textContent = record.unitName;
            let tdElement7 = document.createElement("td");
            tdElement7.textContent = record.leaderName;
            let tdElement8 = document.createElement("td");
            tdElement8.textContent = record.unitPhone;
            let tdElement9 = document.createElement("td");
            tdElement9.textContent = record.teamName;
            let tdElement10 = document.createElement("td");
            tdElement10.textContent = record.substitute;
            let tdElement11 = document.createElement("td");
            let buttonElement1 = document.createElement("button");
            buttonElement1.classList.add("btn", "btn-primary", "btn-sm", "iconfont");
            buttonElement1.style.marginRight = "10px";
            buttonElement1.textContent = "\u{e6f7}编辑";
            buttonElement1.addEventListener("click", async () => {
                updateId = record.id;
                await openEditAthleteDialog(record);
            });
            
            let buttonElement2 = document.createElement("button");
            buttonElement2.classList.add("btn", "btn-danger", "btn-sm", "iconfont");
            buttonElement2.textContent = "\u{e67c}删除";

            let progress = Number(window.sessionStorage.getItem("progress"));
            if(progress<5 && new Date().getTime() < new Date(window.sessionStorage.getItem("competitionTime")).getTime()){
                buttonElement2.addEventListener("click", () => {
                    delId = record.id;
                    openDialog("del-one-group-dialog");
                });
                
            }else{
                buttonElement2.disabled=true
            }

           
            tdElement11.append(buttonElement1, buttonElement2);
            trElement.append(tdElement0,tdElement1, tdElement2, tdElement3, htmlTableCellElement, tdElement4, tdElement5, tdElement6, tdElement7, tdElement8,
                tdElement9, tdElement10, tdElement11);
            tableBody.append(trElement);
        }
    }

    //实现分页的方法
    async function getPage(pageNum, pageSize) {
        let searchInput = document.getElementById("search-input");
        searchAll = searchInput.value;
        let url = new URL(ATHLETE_URL + "/searchAll");
        url.searchParams.set("pageNum", pageNum);
        url.searchParams.set("pageSize", pageSize);
        url.searchParams.set("competitionId", window.sessionStorage.getItem("competitionId"));
        url.searchParams.set("searchAll", searchAll);
        await fetch(url).then(response => {
            if (response.ok && response.headers.get("Content-Type") === "application/json") {
                return response.json();
            } else {
                throw new Error(`未知相应状态 ${response.status}或Content-Type：${response.headers.get("Content-Type")}`);
            }
        }).then(pageInfo => {
            pages = pageInfo.pages;
            total = pageInfo.total;
            records = pageInfo.records;
            if(records.length>0){
                document.getElementById("btn-progress").disabled=false;
                document.getElementById("addAthle").disabled=false
            }else{
                document.getElementById("btn-progress").disabled=true;
                document.getElementById("addAthle").disabled=true
                modifyProgress(ATHLETE_PROGRESS)
            }
            let progress = Number(window.sessionStorage.getItem("progress"));
            if(new Date().getTime() > new Date(window.sessionStorage.getItem("competitionTime")).getTime()){
                document.getElementById("loadAth").disabled=true
                document.getElementById("addAthle").disabled=true
				document.getElementById("del-bh").disabled=true
            }
            drawAthleteTable(records);
        }).catch(error => {
            console.log("分页错误：", error);
        });

    }

    //上一页
    async function prePage() {
        pageNum = pageNum - 1;
        await getPage(pageNum, pageSize);
        createpage(pageNum, pageSize, total, pages);
    }

    //下一页
    async function nextPage() {
        pageNum = pageNum + 1;
        await getPage(pageNum, pageSize);
        createpage(pageNum, pageSize, total, pages)
    }

    //点击切换
    async function handlePage(page) {
        if (page !== pageNum) {
            pageNum = page
            await getPage(pageNum, pageSize);
            createpage(pageNum, pageSize, total, pages);
        }

    }

    /**
     * 改变每页条数
     */
    async function changePageSize(value) {
        pageSize = Number(value);
        await getPage(pageNum, pageSize);
        createpage(pageNum, pageSize, total, pages);
    }

    // 创建分页组件
    async function showPage() {
        await getPage(pageNum, pageSize);
        createpage(pageNum, pageSize, total, pages);
    }

    if (window.sessionStorage.getItem("competitionId")) {
        (async () => {
            await showPage();
        })();
    }
    /**
     个人修改只允许修改姓名，电话，个人项目，不改组别的身份证号
     个人补增只允许选择个人项目，组别，单位，若想报接力，需要入已有接力队伍，不允许创建单位，接力队伍。
     */

</script>
</body>
</html>